package com.qn.common.core.exception;

import com.qn.common.core.constant.enums.ResultCodeEnum;
import lombok.Data;

/**
 * 自定义异常类
 *
 * @author Qning
 * @date 2021/05/30
 */
@Data
public class CustomException extends RuntimeException{
    /**
     * 状态码
     */
    private Integer code;

    /**
     * 接受状态码和消息
     * @param code
     * @param message
     */
    public CustomException(Integer code, String message) {
        super(message);
        this.code=code;
    }

    /**
     * 接收枚举类型
     * @param resultCodeEnum
     */
    public CustomException(ResultCodeEnum resultCodeEnum) {
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "CustomException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }
}
